package com.lzy.cloud.order.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzy.cloud.order.dtos.OrderInfoCarRentDto;
import com.lzy.cloud.order.entity.OrderInfoCarRent;
import com.lzy.cloud.order.mapper.OrderInfoCarRentMapperExt;
import com.lzy.cloud.order.service.OrderInfoCarRentService;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @description:房车租赁订单子表
 * @author: liyun
 * @create: 2018-07-05 16:14
 */
@Service
public class OrderInfoCarRentServiceImpl implements OrderInfoCarRentService {
    @Autowired
    private OrderInfoCarRentMapperExt orderInfoCarRentMapperExt;

    @Override
    public OrderInfoCarRentDto queryByOrderId(String orderId) {
        return orderInfoCarRentMapperExt.queryByOrderId(orderId);
    }

    @Override
    public boolean create(OrderInfoCarRentDto orderInfoCarRentDto) {
        return orderInfoCarRentMapperExt.insertSelective(DozerUtils.map(orderInfoCarRentDto, OrderInfoCarRent.class)) > 0;
    }

    @Override
    public boolean update(OrderInfoCarRentDto orderInfoCarRentDto) {
        return orderInfoCarRentMapperExt.updateByPrimaryKeySelective(DozerUtils.map(orderInfoCarRentDto, OrderInfoCarRent.class)) > 0;
    }

    @Override
    public PageInfo<OrderInfoCarRentDto> selectList(Pager pager, OrderInfoCarRentDto dto) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        return new PageInfo<>(orderInfoCarRentMapperExt.selectList(dto));
    }

    @Override
    public OrderInfoCarRentDto findByCarIdAndRentTime(Long carId, String rentTime) {
        return orderInfoCarRentMapperExt.findByCarIdAndRentTime(carId, rentTime);
    }
}
